package dynamicProgramming;

import java.io.File;
import java.io.FileNotFoundException;
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

import org.zhenhu.CSCE310.KnapSack.KnapSack;

public class ReadknapSack {


	
	public static void readFile(String fileName){
		Scanner read = null;
		
		try{
			read = new Scanner(new File(fileName));
		} catch(FileNotFoundException e){
			e.printStackTrace();
		}
		
		String firstLine = read.nextLine();
		String[] firstLineToken = firstLine.split(" ");
		int size = Integer.parseInt(firstLineToken[0]);
		int maxWeight = Integer.parseInt(firstLineToken[1]);
	
		String line;
		String[] lineToken;
		
		List<Integer> list_weight = new ArrayList<Integer>();
		List<Integer> list_value = new ArrayList<Integer>();
		
		while(read.hasNextLine()){
			line = read.nextLine();
			lineToken = line.split(" ");
			for(int i = 0; i < size; i++){
				if(list_weight.size()==size){
				list_value.add(Integer.parseInt(lineToken[i]));
				}else{
					list_weight.add(Integer.parseInt(lineToken[i]));
				}
				
			}
		}
		
//		System.out.println(list_value);
//		System.out.println(list_weight);
		knapSack test = new knapSack();
		int[][] matrix = test.dynamicKnapSack(list_value, list_weight, maxWeight);
		System.out.println("Resulting table: ");
		test.printMatrix(matrix);
		
		test.solution(list_value, list_weight, maxWeight);
		

		read.close();
	}

	
	
	/**
	 * @param args
	 */
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		ReadknapSack result = new ReadknapSack();
		result.readFile("test_case_010.input.txt");
		
		
		
		
		
		
	}

}
